/* $RCSFile: SimpleImage.ascx.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/AddonNice/PageModules/SimpleImage/SimpleImage.ascx.cs $
 * $log$
 * Revision 25 2010/08/09 10:28:44  christian.surieux
 *   Adding Log comment to ascx files
 * Revision 20 2010/08/09 10:25:54  christian.surieux
 *   Test Comment to ascx
 * Revision 19 2010/08/09 09:43:59  christian.surieux
 *   Added Log to cs sources files
 * Revision 6 2010/08/06 19:56:26  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using AddonNice.UI;
using AddonNice.Diagnostics;
using AddonNice.UI.WebControls;
using AddonNice.UI.DataTypes;
using AddonNice.Configuration;
using AddonNice.Configuration.Settings;

using Trace2    =   System.Diagnostics.Trace;

namespace AddonNice.PageModules.SimpleImage
{
    /// <summary>
    /// Initializer class for SimpleImage 
    /// </summary>
    public class SimpleImageSI : PortalModuleControlSI
    {
        public SimpleImageSI(ModuleSettingsDictionary bSettings,ISettingsOwner pm) : base()
        {
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]SimpleImageSI Ctor BEG.",ModuleTraceSwitch.Sw.Info);
            InitSettings(bSettings,pm);
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]SimpleImageSI Ctor END.",ModuleTraceSwitch.Sw.Info);
        }
 
        public override void InitSettings(ModuleSettingsDictionary bSettings,ISettingsOwner pm)
        {             
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]SimpleImageSI InitSettings BEG.",ModuleTraceSwitch.Sw.Info);
            
            base.InitSettings(bSettings,pm);

			string extgrp               =   pm.ExtendedResourcesGroup;
            
            SettingItemSpecial src      =   new SettingItemSpecial("SIMPLEIMG_SRC2",new UploadedFileDataType2()); //PortalUrlDataType
			src.Required                =   false;
			src.Order                   =   1;
            src.ExtendedGroupName       =   extgrp;
            src.EnglishName             =   "Source file";
            src.Description             =   "Source file";
			bSettings.AddSetting(src);

			SettingItemSpecial width    =   new SettingItemSpecial("SIMPLEIMG_WIDTH",new UnitDataType());
			width.MinValue              =   0;
			width.MaxValue              =   2048;
			width.Value                 =   "150px";
			width.Order                 =   2;
			width.ExtendedGroupName     =   extgrp;
            width.EnglishName           =   "width";
            width.Description           =   "width";
            bSettings.AddSetting(width);

			SettingItemSpecial height   =   new SettingItemSpecial("SIMPLEIMG_HEIGHT",new UnitDataType());
			height.MinValue             =   0;
			height.MaxValue             =   2048;
			height.Value                =   "250px";
			height.Order                =   3;
			height.ExtendedGroupName    =   extgrp;
            height.EnglishName          =   "height";
            height.Description          =   "height";
			bSettings.AddSetting(height);
            
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]SimpleImageSI InitSettings END.",ModuleTraceSwitch.Sw.Info);
        }
    }


	public partial class SimpleImage : PortalModuleControl 
	{

		public override Guid GuidID 
		{
			get
			{
				return new Guid("{BCF1F338-4564-461C-9606-CB024D10294E}");
			}
		}

        public SimpleImage() 
		{                
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]SimpleImage Ctor Called.",ModuleTraceSwitch.Sw.Info);
		}

        public override string ExtendedResourcesGroup 
		{
            get
            {
       			const string extgrp         =   "SIMPLEIMAGE";
                return extgrp;
            }
		}

        public override void InitPortalModuleControl(ModuleSettingsDictionary bSettings)
        {
            PortalModuleInitializer =   new SimpleImageSI(bSettings,this);
        }

        /// <summary>
		/// The Page_Load event handler on this User Control uses
		/// the Portal configuration system to obtain image details.
		/// It then sets these properties on an &lt;asp:Image&gt; server control.
		/// </summary>
		private void Page_Load(object sender, System.EventArgs e) 
		{
			string imageSrc     =   Settings["SIMPLEIMG_SRC2"].FullPath;

			// Set Image Source, Width and Height Properties
			if (!string.IsNullOrEmpty(imageSrc)) 
			{
				Image1.ImageUrl =   imageSrc;
			}

            if (Settings.ContainsKeyNotEmpty("SIMPLEIMG_HEIGHT") ) 
			{
				Image1.Width = Settings["SIMPLEIMG_HEIGHT"].ToUnit();
			}

            if (Settings.ContainsKeyNotEmpty("SIMPLEIMG_WIDTH") ) 
			{
				Image1.Height = Settings["SIMPLEIMG_WIDTH"].ToUnit();
			}
		}
 

		#region Std Overrides

        override protected void OnInit(EventArgs e)
		{
			InitializeComponent();
			base.OnInit(e);
		}

		private void InitializeComponent() 
		{
			this.Load += new System.EventHandler(this.Page_Load);
		}

        #endregion
	}
}
